package IO;

import java.io.*;

public class Copy2 {
    public static void main(String[] args) throws IOException {
            copy("day10-file_io/src/File3.txt","day10-file_io/src/File4.txt");
    }
    public static void copy(String src,String dest) throws IOException {
            try (InputStream  in = new FileInputStream(src);
                 OutputStream  out = new FileOutputStream(dest);//用完自动调close
                 ){
                byte[] buffer = new byte[1024];
                int len;
                while ((len = in.read(buffer)) != -1) {
                    out.write(buffer, 0, len);
                }
                System.out.println("File copied successfully");

            } catch (IOException e) {
                throw new RuntimeException(e);
            }
    }
}
